#include "realnumber.h"

RealNumber::RealNumber()  : FormulaElement() {
    value=new double(0);
}

RealNumber::~RealNumber() {
    delete value;
}

const double& RealNumber::getValue() {
    return *value;
}

RealNumber::RealNumber(const double& newValue) : FormulaElement() {
    value=new double(newValue);
}

std::string& RealNumber::toString() {
    return DoubleToString::dts(*value);
}

void RealNumber::evaluateMe(LinkedList<double>& evaluationStack, const double* positionArray) {
    evaluationStack.addAtEnd(*(new double(*value)));
}

void RealNumber::mutate() {
        double& temp=RealNumber::getRealRandomNumber(25,31);
        double& bigTemp=RealNumber::getRealRandomNumber(22,240);
        switch(rand()>>28) { // 0 to 7 with boarders
            case 0:
                (*value)+=temp;
                break;
            case 1:
                (*value)*=temp/10.000;
                break;
            case 2:
                (*value)*=temp/60.000;
                break;
            case 3:
                (*value)*=temp/1.836;
                break;
            case 4:
                (*value)-=bigTemp;
                break;
            case 5:
                (*value)=temp;
                break;
            case 6:
                (*value)=bigTemp;
                break;
            case 7:
                break;
            default:
                assert(false);
        }
        delete &temp;
        delete &bigTemp;
}

bool operator==(RealNumber& r1, RealNumber& r2) {
	return (*r1.value)==(*r2.value);
}

FormulaElement& RealNumber::copy() {
    return *(new RealNumber(*this));
}

RealNumber::RealNumber(RealNumber& myRealNumber) {
    value=new double(myRealNumber.getValue());
}

void RealNumber::createHumanReadeableToString(LinkedList<std::string>& toStringStack) {
    toStringStack.addAtEnd(toString());
}
